Return to start page

Systems/Gui/Struct Main Window.j

Code

		
1			library AStructSystemsGuiMainWindow requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable, AStructCoreGeneralVector, ALibraryCoreInterfaceCamera, ALibraryCoreInterfaceCinematic, ALibraryCoreInterfaceTextTag, ALibraryCoreInterfaceMisc, ALibraryCoreEnvironmentSound, ALibraryCoreMathsRect, AStructSystemsGuiWidget
2
3 /// @todo Should be a static function interface of @struct AMainWindow, vJass bug.
4 function interface AMainWindowOnShowCondition takes AMainWindow mainWindow returns boolean
5
6 /// @todo Should be a static function interface of @struct AMainWindow, vJass bug.
7 function interface AMainWindowOnShowAction takes AMainWindow mainWindow returns nothing
8
9 /// @todo Should be a static function interface of @struct AMainWindow, vJass bug.
10 function interface AMainWindowOnHideCondition takes AMainWindow mainWindow returns boolean
11
12 /// @todo Should be a static function interface of @struct AMainWindow, vJass bug.
13 function interface AMainWindowOnHideAction takes AMainWindow mainWindow returns nothing
14
15 struct AMainWindow
16 //static start members
17 private static camerasetup cameraSetup
18 private static string tooltipSoundPath
19 //dynamic members
20 private AMainWindowOnShowCondition m_onShowCondition
21 private AMainWindowOnShowAction m_onShowAction
22 private AMainWindowOnHideCondition m_onHideCondition
23 private AMainWindowOnHideAction m_onHideAction
24 private real m_tooltipX
25 private real m_tooltipY
26 //start members
27 private AGui m_gui
28 private real m_x
29 private real m_y
30 private real m_sizeX
31 private real m_sizeY
32 private boolean m_useShortcuts
33 private integer m_shortcut
34 //members
35 private integer m_index
36 private boolean m_isShown
37 private AIntegerVector m_widgets
38 private texttag m_tooltip
39 private trigger m_shortcutTrigger
40 private rect m_fogModifierRect
41 private fogmodifier m_visibilityModifier
42 private fogmodifier m_blackMaskModifier
43
44 //! runtextmacro optional A_STRUCT_DEBUG("\"AMainWindow\"")
45
46 //dynamic members
47
48 /// The @param onShowCondition will be checked before the main window should be displayed.
49 /// If it returns false the main window won't be displayed.
50 public method setOnShowCondition takes AMainWindowOnShowAction onShowCondition returns nothing
51 set this.m_onShowCondition = onShowCondition
52 endmethod
53
54 public method onShowCondition takes nothing returns AMainWindowOnShowCondition
55 return this.m_onShowCondition
56 endmethod
57
58 public method setOnShowAction takes AMainWindowOnShowAction onShowAction returns nothing
59 set this.m_onShowAction = onShowAction
60 endmethod
61
62 public method onShowAction takes nothing returns AMainWindowOnShowAction
63 return this.m_onShowAction
64 endmethod
65
66 public method setOnHideCondition takes AMainWindowOnHideCondition onHideCondition returns nothing
67 set this.m_onHideCondition = onHideCondition
68 endmethod
69
70 public method onHideCondition takes nothing returns AMainWindowOnHideCondition
71 return this.m_onHideCondition
72 endmethod
73
74 public method setOnHideAction takes AMainWindowOnHideAction onHideAction returns nothing
75 set this.m_onHideAction = onHideAction
76 endmethod
77
78 public method onHideAction takes nothing returns AMainWindowOnHideAction
79 return this.m_onHideAction
80 endmethod
81
82 public method setTooltipX takes real tooltipX returns nothing
83 set this.m_tooltipX = tooltipX
84 endmethod
85
86 public method tooltipX takes nothing returns real
87 return this.m_tooltipX
88 endmethod
89
90 public method setTooltipY takes real tooltipY returns nothing
91 set this.m_tooltipY = tooltipY
92 endmethod
93
94 public method tooltipY takes nothing returns real
95 return this.m_tooltipY
96 endmethod
97
98 //start members
99
100 public method gui takes nothing returns AGui
101 return this.m_gui
102 endmethod
103
104 public method x takes nothing returns real
105 return this.m_x
106 endmethod
107
108 public method y takes nothing returns real
109 return this.m_y
110 endmethod
111
112 public method sizeX takes nothing returns real
113 return this.m_sizeX
114 endmethod
115
116 public method sizeY takes nothing returns real
117 return this.m_sizeY
118 endmethod
119
120 //members
121
122 public method index takes nothing returns integer
123 return this.m_index
124 endmethod
125
126 public method isShown takes nothing returns boolean
127 return this.m_isShown
128 endmethod
129
130 //convenience methods
131
132 public method user takes nothing returns player
133 return this.m_gui.user()
134 endmethod
135
136 //methods
137
138 public method getX takes real x returns real
139 return (this.m_x + x)
140 endmethod
141
142 public method getY takes real y returns real
143 return (this.m_y - y)
144 endmethod
145
146 public method enableShortcut takes nothing returns nothing
147 debug if (this.m_shortcut == -1) then
148 debug call this.print("Main window does not use a shortcut.")
149 debug return
150 debug endif
151 call EnableTrigger(this.m_shortcutTrigger)
152 endmethod
153
154 public method disableShortcut takes nothing returns nothing
155 debug if (this.m_shortcut == -1) then
156 debug call this.print("Main window does not use a shortcut.")
157 debug return
158 debug endif
159 call DisableTrigger(this.m_shortcutTrigger)
160 endmethod
161
162 public method showTooltip takes AWidget usedWidget returns nothing
163 if (this.m_tooltip == null) then
164 set this.m_tooltip = CreateTextTag()
165 call SetTextTagVisibility(this.m_tooltip, false)
166 endif
167 call SetTextTagTextBJ(this.m_tooltip, usedWidget.tooltip(), usedWidget.tooltipSize())
168 call SetTextTagPos(this.m_tooltip, this.getX(this.m_tooltipX), this.getY(this.m_tooltipY), 0.0)
169 call ShowTextTagForPlayer(this.user(), this.m_tooltip, true)
170 if (thistype.tooltipSoundPath != null) then
171 call PlaySoundPathForPlayer(this.user(), thistype.tooltipSoundPath)
172 endif
173 endmethod
174
175 public method hideTooltip takes nothing returns nothing
176 if (this.m_tooltip != null) then
177 call ShowTextTagForPlayer(this.user(), this.m_tooltip, false)
178 endif
179 endmethod
180
181 public method show takes nothing returns nothing
182 local real x
183 local real y
184 local integer i
185 if (this.m_onShowCondition != 0 and not this.m_onShowCondition.evaluate(this)) then
186 return
187 endif
188 set x = this.m_x + (this.m_sizeX / 2.0)
189 set y = this.m_y - (this.m_sizeY / 2.0)
190 call this.m_gui.savePlayerData()
191 call FogModifierStop(this.m_blackMaskModifier)
192 call FogModifierStart(this.m_visibilityModifier)
193 call ClearScreenMessagesForPlayer(this.user())
194 call CameraSetupApplyForPlayer(false, thistype.cameraSetup, this.user(), 0.0)
195 call PanCameraToTimedForPlayer(this.user(), x, y, 0.0)
196 call SetCameraBoundsToPointForPlayer(this.user(), x, y) /// @todo DEBUG
197 //widgets
198 set i = 0
199 loop
200 exitwhen (i == this.m_widgets.size())
201 call AWidget(this.m_widgets[i]).show()
202 set i = i + 1
203 endloop
204
205 if (this.m_useShortcuts) then
206 call this.m_gui.enableShortcuts()
207 endif
208 set this.m_isShown = true
209 call this.m_gui.hideShownMainWindowAndSetNew(this)
210 if (this.m_onShowAction != 0) then
211 call this.m_onShowAction.execute(this)
212 endif
213 endmethod
214
215 public method hide takes nothing returns nothing
216 local integer i
217 if (this.m_onHideCondition != 0 and not this.m_onHideCondition.evaluate(this)) then
218 return
219 endif
220
221 call ResetCameraBoundsToMapRectForPlayer(this.user())
222 call ResetToGameCameraForPlayer(this.user(), 0.0)
223 call FogModifierStop(this.m_visibilityModifier)
224 call FogModifierStart(this.m_blackMaskModifier)
225 call this.m_gui.loadPlayerData() /// @todo DESYNC
226 call this.hideTooltip()
227 //widgets
228 set i = 0
229 loop
230 exitwhen (i == this.m_widgets.size())
231 call AWidget(this.m_widgets[i]).hide()
232 set i = i + 1
233 endloop
234
235 if (this.m_useShortcuts) then
236 call this.m_gui.disableShortcuts()
237 endif
238 set this.m_isShown = false
239 call this.m_gui.resetShownMainWindow()
240
241 if (this.m_onHideAction != 0) then
242 call this.m_onHideAction.execute(this)
243 endif
244 endmethod
245
246 /// Friend relationship to @struct AWidget, do not use.
247 public method dockWidget takes AWidget usedWidget returns integer
248 call this.m_widgets.pushBack(usedWidget)
249 return this.m_widgets.backIndex()
250 endmethod
251
252 /// Friend relationship to @struct AWidget, do not use.
253 public method undockWidgetByIndex takes integer index returns nothing
254 call this.m_widgets.erase(index)
255 endmethod
256
257 private static method triggerActionPressShortcut takes nothing returns nothing
258 local trigger triggeringTrigger = GetTriggeringTrigger()
259 local thistype this = AHashTable.global().handleInteger(triggeringTrigger, "this")
260 if (not this.m_isShown) then
261 call this.show()
262 else
263 call this.hide()
264 endif
265 set triggeringTrigger = null
266 endmethod
267
268 private method createShortcutTrigger takes nothing returns nothing
269 local event triggerEvent
270 local triggeraction triggerAction
271 set this.m_shortcutTrigger = CreateTrigger()
272 set triggerEvent = TriggerRegisterKeyEventForPlayer(this.user(), this.m_shortcutTrigger, this.m_shortcut, true)
273 set triggerAction = TriggerAddAction(this.m_shortcutTrigger, function thistype.triggerActionPressShortcut)
274 call AHashTable.global().setHandleInteger(this.m_shortcutTrigger, "this", this)
275 set triggerEvent = null
276 set triggerAction = null
277 endmethod
278
279 /// @param shortcut If this value is -1 main window won't have any shortcut.
280 public static method create takes AGui gui, real x, real y, real sizeX, real sizeY, boolean useShortcuts, integer shortcut returns thistype
281 local thistype this = thistype.allocate()
282 //dynamic members
283 set this.m_onShowCondition = 0
284 set this.m_onShowAction = 0
285 set this.m_onHideCondition = 0
286 set this.m_onHideAction = 0
287 set this.m_tooltipX = 0.0
288 set this.m_tooltipY = 0.0
289 //start members
290 set this.m_gui = gui
291 set this.m_x = x //insert a debug if the coordinates are out of map range
292 set this.m_y = y
293 set this.m_sizeX = sizeX
294 set this.m_sizeY = sizeY
295 set this.m_useShortcuts = useShortcuts
296 set this.m_shortcut = shortcut
297 //members
298 set this.m_index = gui.dockMainWindow(this)
299 set this.m_widgets = AIntegerVector.create()
300 set this.m_isShown = false
301 set this.m_fogModifierRect = RectFromPointSize(this.m_x + this.m_sizeX / 2.0, this.m_y - this.m_sizeY / 2.0, this.m_sizeX, this.m_sizeY)
302 set this.m_visibilityModifier = CreateFogModifierRect(this.user(), FOG_OF_WAR_VISIBLE, this.m_fogModifierRect, true, false)
303 set this.m_blackMaskModifier = CreateFogModifierRect(this.user(), FOG_OF_WAR_MASKED, this.m_fogModifierRect, true, false)
304 call FogModifierStart(this.m_blackMaskModifier)
305
306 if (shortcut != -1) then
307 debug if (not KeyIsValid(shortcut)) then
308 debug call this.print("Shortcut has no valid key value.")
309 debug endif
310 call this.createShortcutTrigger()
311 endif
312 return this
313 endmethod
314
315 public static method createByRect takes AGui gui, rect usedRect, boolean useShortcuts, integer shortcut returns AMainWindow
316 return thistype.create(gui, GetRectMinX(usedRect), GetRectMaxY(usedRect), GetRectWidthBJ(usedRect), GetRectHeightBJ(usedRect), useShortcuts, shortcut)
317 endmethod
318
319 public method onDestroy takes nothing returns nothing
320 call this.m_gui.undockMainWindowByIndex(this.m_index)
321 //members
322 if (this.m_tooltip != null) then
323 call DestroyTextTag(this.m_tooltip)
324 set this.m_tooltip = null
325 endif
326 call RemoveRect(this.m_fogModifierRect)
327 set this.m_fogModifierRect = null
328 call DestroyFogModifier(this.m_visibilityModifier)
329 set this.m_visibilityModifier = null
330 call DestroyFogModifier(this.m_blackMaskModifier)
331 set this.m_blackMaskModifier = null
332
333 if (this.m_shortcut != -1) then
334 call AHashTable.global().destroyTrigger(this.m_shortcutTrigger)
335 set this.m_shortcutTrigger = null
336 endif
337
338 loop
339 exitwhen (this.m_widgets.empty())
340 call AWidget(this.m_widgets.back()).destroy()
341 /// @todo don't pop back, is in destructor, check for errors
342 endloop
343 call this.m_widgets.destroy()
344 endmethod
345
346 /// @param cameraSetup The camera setup which is used as the players view on the main window.
347 /// @param tooltipSoundPath The path of the sound which is played when player drags the cursor over the related object. If this value is null there won't be played any sound.
348 public static method init takes camerasetup cameraSetup, string tooltipSoundPath returns nothing
349 set thistype.cameraSetup = cameraSetup
350 set thistype.tooltipSoundPath = tooltipSoundPath
351
352 if (tooltipSoundPath != null) then
353 call PreloadSoundPath(tooltipSoundPath) //ALibraryEnvironmentSound
354 endif
355 endmethod
356 endstruct
357
358 endlibrary
359